import { Component, OnInit, ViewChild } from '@angular/core';
import { STColumn, STColumnButton, STComponent, STData } from '@delon/abc/st';
import { SFComponent, SFSchema, SFUISchema } from '@delon/form';
import { ModalHelper, _HttpClient } from '@delon/theme';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { SupplyManagementService } from '../../services/supply-management.service';

@Component({
  selector: 'app-supply-management-add-drivers',
  templateUrl: './add-drivers.component.html',
})
export class SupplyManagementAddDriversComponent implements OnInit {
  url = `/user?_allow_anonymous=true`;
  i: any;
  searchSchema: SFSchema = {};
  @ViewChild('st') private readonly st!: STComponent;
  @ViewChild('sf') sf!: SFComponent;
  ui: SFUISchema = {}
  columns: STColumn[] = [];
  isVisible = false;
  diverList: object[] = [];
  dirvierInfo: any = {};
  constructor(public service: SupplyManagementService, private modal: NzModalRef) { }

  ngOnInit(): void {
    this.initSF();
    this.initST();
  }

  /**
* 查询参数
*/
  get reqParams() {
    return {
      ...this.sf?.value
    };
  }
  /**
* 初始化查询表单
*/
  initSF() {
    this.searchSchema = {
      properties: {
        mobile: {
          type: 'string',
          title: '车队长手机号',
          ui: {
            placeholder: '请输入'
          }
        },
      },
      type: 'object',
    };
    this.ui = { '*': { spanLabelFixed: 80, grid: { span: 8, gutter: 4 } } };
  }

  /**
   * 初始化数据列表
   */
  initST() {
    this.columns = [
      {
        title: '司机头像',
        width: '100px',
        className: 'text-center',
        index: 'avatar',
        type: 'img',
      },
      { title: '司机姓名', index: 'name', width: '120px', className: 'text-center' },
      { title: '实名认证状态', index: 'linkUrl', width: '120px', className: 'text-center' },
      {
        title: '操作',
        fixed: 'right',
        width: '200px',
        className: 'text-center',
        buttons: [
          {
            text: '设置',
            click: (_record) => this.addCaptain(_record)
            // iif: (item: STData, btn: STColumnButton, column: STColumn) => item?.status > 0,
          },
        ],
      },
    ];
  }



  search() {
    this.getDriverList();
  }


  getDriverList() {
    this.service.request(this.service.$api_get_car_captain_by_mobile, { ...this.sf?.value }).subscribe((res: any) => {
      this.diverList = [];
      if (res.userId) {
        this.diverList.push(res);
      }
      // this.st.reload();
    })
  }


  /**
   *
   */
  addCaptain(item: any) {
    this.modal.close(item); // 虚设置车队长
    // const { appUserId: carCaptain } = item;
    // const { appUserId } = this.dirvierInfo;
    // this.service.request(this.service.$api_add_car_caption, { carCaptain, appUserId }).subscribe(res => {
    //   if (res) {
    //     this.service.msgSrv.success('设置成功');
    //     this.modal.close(true);
    //   }
    // })
  }

}
